home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / Duck Report / _SETUP.1 / Main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-10-23  |  9.6 KB  |  408 lines

  1. unit Main;
  2. {.$I DRLib.inc}
  3.  
  4. interface
  5.  
  6. uses
  7.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  8.   DBTables, StdCtrls, ExtCtrls, DREng, DRBase;
  9. Const
  10.     TEXT_RETURN        = Char(#13) + Char(#10);
  11. type
  12.   TFormMain = class(TForm)
  13.     Image2: TImage;
  14.     MemoShow: TMemo;
  15.     BPrint: TButton;
  16.     BPreview: TButton;
  17.     DReport: TDuckReport;
  18.     RGType: TRadioGroup;
  19.     procedure FormCreate(Sender: TObject);
  20.     procedure BPrintClick(Sender: TObject);
  21.     procedure BPreviewClick(Sender: TObject);
  22.   private
  23.         Procedure    ShowErrorAlias;
  24.      Procedure    WMCustom (Var Message: TMessage); Message WM_USER + 100;
  25.      Procedure    Customer (bPrint: Boolean);
  26.      Procedure    Order (bPrint: Boolean);
  27.      Procedure    Invoice (bPrint: Boolean);
  28.      Procedure    MailLabel (bPrint: Boolean);
  29.      Procedure    Envelope (bPrint: Boolean);
  30.      Procedure    BioLife (bPrint: Boolean);
  31.      Procedure    Barcode (bPrint: Boolean);
  32.      Procedure    Lookup (bPrint: Boolean);
  33.      Procedure    RichBioLife (bPrint: Boolean);
  34.      Procedure    SummaryPayment (bPrint: Boolean);
  35.      Procedure    SummaryShipVIA (bPrint: Boolean);
  36.      Procedure    FormulaPayment (bPrint: Boolean);
  37.      Procedure    FormulaShipVIA (bPrint: Boolean);
  38.      Procedure    ChartPayment (bPrint: Boolean);
  39.      Procedure    ChartShipVIA (bPrint: Boolean);
  40.      Procedure    ChartSummary (bPrint: Boolean);
  41.      Procedure    ChartMonth (bPrint: Boolean);
  42.      Procedure    ChartYear (bPrint: Boolean);
  43.   public
  44.   end;
  45.  
  46. var
  47.   FormMain: TFormMain;
  48.  
  49. implementation
  50.  
  51. uses FOrder, FYear;
  52.  
  53. {$R *.DFM}
  54. Procedure TFormMain.FormCreate(Sender: TObject);
  55. Var
  56.     St:            String;
  57.   StAlias:        String;
  58.   Database:    TDatabase;
  59.     List:            TStringList;
  60.   iPos:            Integer;
  61. Begin
  62.     St    := 'Duck Report Version ' + Display_VERSION;
  63.     {$IFDEF DRVERSION_FREE}
  64.         St    := St + ' (Freeware)';
  65.     {$ELSE}
  66.         {$IFDEF DRVERSION_REGISTER}
  67.          St    := St + ' (Register)';
  68.       {$ELSE}    { DRVERSION_FULL }
  69.      St    := St + ' (License)';
  70.       {$ENDIF}
  71.   {$ENDIF}
  72.     MemoShow.Lines.Insert (0, St);
  73.   MemoShow.Lines.Insert (1, 'Copyright (c) 1998');
  74.  
  75.  
  76.     StAlias    := 'DRDEMOS';
  77.     St    := Application.ExeName;
  78.     St    := ExtractFileDir (St);
  79.     St    := UpperCase (St);
  80.     DReport.Directory    := St;
  81.   List        := TStringList.Create;
  82.   Session.GetAliasNames (List);
  83.   iPos    := List.IndexOf (StAlias);
  84.     if iPos <= 0 Then
  85.     Begin
  86.       iPos    := Pos ('\DEMOS\DEMO1', St);
  87.       if iPos <= 0 Then
  88.      Begin
  89.          ShowErrorAlias;
  90.      End;
  91.      Delete (St, iPos, Length (St) - iPos + 1);
  92.      St        := St + '\DATA';
  93.         List.Clear;
  94.      List.Add ('PATH =' + St);
  95.      List.Add ('DEFAULT DRIVER =PARADOX');
  96.      Try
  97.          Session.AddAlias (StAlias, 'PARADOX', List);
  98.      Finally
  99.         Session.SaveConfigFile;
  100.      End;
  101.   End;
  102.   List.Free;
  103. End;
  104. Procedure TFormMain.ShowErrorAlias;
  105. Begin
  106.     MessageBeep (0);
  107.     MessageDlg ('Please Apppend BDE Alias DRDEMOS.' + TEXT_RETURN +
  108.                      'And Setup Path to <Duck Report Dir.>\Data',
  109.                  mtError, [mbOK],0);
  110.     PostMessage (Self.Handle, WM_USER + 100, 0, 0);
  111. End;
  112. Procedure TFormMain.WMCustom (Var Message: TMessage);
  113. Begin
  114.     Close;
  115. End;
  116. Procedure TFormMain.BPrintClick(Sender: TObject);
  117. Begin
  118.     Case RGType.ItemIndex of
  119.          0:    Customer(TRUE);
  120.          1:    Order(TRUE);
  121.        2:    Invoice(TRUE);
  122.        3:    MailLabel(TRUE);
  123.        4:    Envelope(TRUE);
  124.        5:    BioLife(TRUE);
  125.        6:    Barcode(TRUE);
  126.        7:    Lookup(TRUE);
  127.        8:    RichBioLife(TRUE);
  128.        9:    SummaryPayment(TRUE);
  129.         10:    SummaryShipVIA(TRUE);
  130.         11:    FormulaPayment(TRUE);
  131.         12:    FormulaShipVIA(TRUE);
  132.         13:    ChartPayment(TRUE);
  133.         14:    ChartShipVIA(TRUE);
  134.         15:    ChartSummary(TRUE);
  135.         16:    ChartMonth(TRUE);
  136.         17:    ChartYear(TRUE);
  137.     End;
  138. End;
  139. Procedure TFormMain.BPreviewClick(Sender: TObject);
  140. Begin
  141.     Case RGType.ItemIndex of
  142.          0:    Customer(FALSE);
  143.          1:    Order(FALSE);
  144.        2:    Invoice(FALSE);
  145.        3:    MailLabel(FALSE);
  146.        4:    Envelope(FALSE);
  147.        5:    BioLife(FALSE);
  148.        6:    Barcode(FALSE);
  149.        7:    Lookup(FALSE);
  150.        8:    RichBioLife(FALSE);
  151.        9:    SummaryPayment(FALSE);
  152.         10:    SummaryShipVIA(FALSE);
  153.         11:    FormulaPayment(FALSE);
  154.         12:    FormulaShipVIA(FALSE);
  155.         13:    ChartPayment(FALSE);
  156.         14:    ChartShipVIA(FALSE);
  157.         15:    ChartSummary(FALSE);
  158.         16:    ChartMonth(FALSE);
  159.         17:    ChartYear(FALSE);
  160.     End;
  161. End;
  162. Procedure TFormMain.Customer (bPrint: Boolean);
  163. Begin
  164.     DReport.Filter        := '';
  165.     DReport.FileName    := 'Customer.DRP';
  166.     DReport.OpenFile;
  167.     DReport.OpenDB;
  168.     if bPrint Then
  169.       DReport.Print
  170.     Else
  171.         DReport.Preview;
  172. End;
  173. Procedure TFormMain.Order (bPrint: Boolean);
  174. Begin
  175.     DReport.Filter        := '';
  176.     DReport.FileName    := 'Order.DRP';
  177.     DReport.OpenFile;
  178.     DReport.OpenDB;
  179.     if bPrint Then
  180.       DReport.Print
  181.     Else
  182.         DReport.Preview;
  183. End;
  184. Procedure TFormMain.Invoice (bPrint: Boolean);
  185. Var
  186.     dOrder:    Double;
  187. Begin
  188.     dOrder        := 0;
  189.     FormOrderNo    := TFormOrderNo.Create (Self);
  190.   FormOrderNo.ShowModal;
  191.   if FormOrderNo.ModalResult = mrOK Then
  192.   Begin
  193.       dOrder    := FormOrderNo.dOrder; 
  194.   End;
  195.   FormOrderNo.Free;
  196.  
  197.   if dOrder = 0 Then Exit;
  198.  
  199.     DReport.Filter        := '';
  200.     DReport.FileName    := 'Invoice.DRP';
  201.     DReport.OpenFile;
  202.   DReport.Variables.ByName['OrderNo'].AsDouble    := dOrder;
  203.     DReport.OpenDB;
  204.     if bPrint Then
  205.       DReport.Print
  206.     Else
  207.         DReport.Preview;
  208. End;
  209. Procedure TFormMain.MailLabel (bPrint: Boolean);
  210. Begin
  211.     DReport.Filter        := '';
  212.     DReport.FileName    := 'Label.DRP';
  213.     DReport.OpenFile;
  214.     DReport.OpenDB;
  215.     if bPrint Then
  216.       DReport.Print
  217.     Else
  218.         DReport.Preview;
  219. End;
  220. Procedure TFormMain.Envelope (bPrint: Boolean);
  221. Begin
  222.     DReport.Filter        := '';
  223.     DReport.FileName    := 'Envelope.DRP';
  224.     DReport.OpenFile;
  225.     DReport.OpenDB;
  226.     if bPrint Then
  227.       DReport.Print
  228.     Else
  229.         DReport.Preview;
  230. End;
  231. Procedure TFormMain.BioLife (bPrint: Boolean);
  232. Begin
  233.     DReport.Filter        := '';
  234.     DReport.FileName    := 'BioLife.DRP';
  235.     DReport.OpenFile;
  236.     DReport.OpenDB;
  237.     if bPrint Then
  238.       DReport.Print
  239.     Else
  240.         DReport.Preview;
  241. End;
  242. Procedure TFormMain.Barcode (bPrint: Boolean);
  243. Begin
  244.     DReport.Filter        := '';
  245.     DReport.FileName    := 'Barcode.DRP';
  246.     DReport.OpenFile;
  247.     DReport.OpenDB;
  248.     if bPrint Then
  249.       DReport.Print
  250.     Else
  251.         DReport.Preview;
  252. End;
  253. Procedure TFormMain.Lookup (bPrint: Boolean);
  254. Begin
  255.     DReport.Filter        := '';
  256.     DReport.FileName    := 'Lookup.DRP';
  257.     DReport.OpenFile;
  258.     DReport.OpenDB;
  259.     if bPrint Then
  260.       DReport.Print
  261.     Else
  262.         DReport.Preview;
  263. End;
  264. Procedure TFormMain.RichBioLife (bPrint: Boolean);
  265. Begin
  266.     DReport.Filter        := '';
  267.     DReport.FileName    := 'RichBioLife.DRP';
  268.     DReport.OpenFile;
  269.     DReport.OpenDB;
  270.     if bPrint Then
  271.       DReport.Print
  272.     Else
  273.         DReport.Preview;
  274. End;
  275. Procedure TFormMain.SummaryPayment (bPrint: Boolean);
  276. Var
  277.     iYear:        Integer;
  278. Begin
  279.     iYear            := 0;
  280.     FormYear        := TFormYear.Create (Self);
  281.   FormYear.ShowModal;
  282.   if FormYear.ModalResult = mrOK Then
  283.       iYear    := FormYear.iYear;
  284.   FormYear.Free;
  285.     if iYear = 0 Then Exit;
  286.     DReport.Filter        := '';
  287.     DReport.FileName    := 'SummaryPayment.DRP';
  288.     DReport.OpenFile;
  289.     DReport.Variables.ByName['StartDate'].AsDateTime    := EncodeDate (iYear, 01, 01);
  290.   DReport.Variables.ByName['EndDate'].AsDateTime    := EncodeDate (iYear, 12, 31);
  291.     DReport.OpenDB;
  292.     if bPrint Then
  293.       DReport.Print
  294.     Else
  295.         DReport.Preview;
  296. End;
  297. Procedure TFormMain.SummaryShipVIA (bPrint: Boolean);
  298. Begin
  299.     DReport.Filter        := '';
  300.     DReport.FileName    := 'SummaryShipVIA.drp';
  301.     DReport.OpenFile;
  302.     DReport.OpenDB;
  303.     if bPrint Then
  304.       DReport.Print
  305.     Else
  306.         DReport.Preview;
  307. End;
  308. Procedure TFormMain.FormulaPayment (bPrint: Boolean);
  309. Var
  310.     iYear:        Integer;
  311. Begin
  312.     iYear            := 0;
  313.     FormYear        := TFormYear.Create (Self);
  314.   FormYear.ShowModal;
  315.   if FormYear.ModalResult = mrOK Then
  316.       iYear    := FormYear.iYear;
  317.   FormYear.Free;
  318.     if iYear = 0 Then Exit;
  319.     DReport.Filter        := '';
  320.     DReport.FileName    := 'FormulaPayment.DRP';
  321.     DReport.OpenFile;
  322.     DReport.Variables.ByName['StartDate'].AsDateTime    := EncodeDate (iYear, 01, 01);
  323.   DReport.Variables.ByName['EndDate'].AsDateTime    := EncodeDate (iYear, 12, 31);
  324.     DReport.OpenDB;
  325.     if bPrint Then
  326.       DReport.Print
  327.     Else
  328.         DReport.Preview;
  329. End;
  330. Procedure TFormMain.FormulaShipVIA (bPrint: Boolean);
  331. Begin
  332.     DReport.Filter        := '';
  333.     DReport.FileName    := 'FormulaShipVIA.drp';
  334.     DReport.OpenFile;
  335.     DReport.OpenDB;
  336.     if bPrint Then
  337.       DReport.Print
  338.     Else
  339.         DReport.Preview;
  340. End;
  341. Procedure TFormMain.ChartPayment (bPrint: Boolean);
  342. Var
  343.     iYear:        Integer;
  344. Begin
  345.     iYear            := 0;
  346.     FormYear        := TFormYear.Create (Self);
  347.   FormYear.ShowModal;
  348.   if FormYear.ModalResult = mrOK Then
  349.       iYear    := FormYear.iYear;
  350.   FormYear.Free;
  351.     if iYear = 0 Then Exit;
  352.     DReport.Filter        := '';
  353.     DReport.FileName    := 'ChartPayment.DRP';
  354.     DReport.OpenFile;
  355.     DReport.Variables.ByName['StartDate'].AsDateTime    := EncodeDate (iYear, 01, 01);
  356.   DReport.Variables.ByName['EndDate'].AsDateTime    := EncodeDate (iYear, 12, 31);
  357.     DReport.OpenDB;
  358.     if bPrint Then
  359.       DReport.Print
  360.     Else
  361.         DReport.Preview;
  362. End;
  363. Procedure TFormMain.ChartShipVIA (bPrint: Boolean);
  364. Begin
  365.     DReport.Filter        := '';
  366.     DReport.FileName    := 'ChartShipVIA.drp';
  367.     DReport.OpenFile;
  368.     DReport.OpenDB;
  369.     if bPrint Then
  370.       DReport.Print
  371.     Else
  372.         DReport.Preview;
  373. End;
  374. Procedure TFormMain.ChartSummary (bPrint: Boolean);
  375. Begin
  376.     DReport.Filter        := '';
  377.     DReport.FileName    := 'ChartSummary.drp';
  378.     DReport.OpenFile;
  379.     DReport.OpenDB;
  380.     if bPrint Then
  381.       DReport.Print
  382.     Else
  383.         DReport.Preview;
  384. End;
  385. Procedure TFormMain.ChartMonth (bPrint: Boolean);
  386. Begin
  387.     DReport.Filter        := '';
  388.     DReport.FileName    := 'ChartMonth.drp';
  389.     DReport.OpenFile;
  390.     DReport.OpenDB;
  391.     if bPrint Then
  392.       DReport.Print
  393.     Else
  394.         DReport.Preview;
  395. End;
  396. Procedure TFormMain.ChartYear (bPrint: Boolean);
  397. Begin
  398.     DReport.Filter        := '';
  399.     DReport.FileName    := 'ChartYear.drp';
  400.     DReport.OpenFile;
  401.     DReport.OpenDB;
  402.     if bPrint Then
  403.       DReport.Print
  404.     Else
  405.         DReport.Preview;
  406. End;
  407. End.
  408.